﻿using System.ComponentModel.Composition;
using Cubicle.Core.Interfaces;

namespace Cubicle.Core.Processors.Invoke
{
    [Export("Cubicle.Processors.Invoke.TargetResolutionProcessor", typeof(IProcessor<InstructionRequest>))]
    [ExportMetadata("Name", "TargetResolutionProcessor")]
    [ExportMetadata("Description", "Determines whether the target is a static or virtual member")]
    public class TargetResolutionProcessor : InstructionRequestProcessor
    {

        [Import]
        private IRepository _repo;

        public TargetResolutionProcessor() : base(RequestType.AllNonSpecial) { }

        public override InstructionRequest ConditionalProcess(InstructionRequest request)
        {
            var obj = _repo.Get(request.Inst.Handle);
            request.Target = obj;
            request.Type(request.Type().Subtract(obj == null ? RequestType.Virtual : RequestType.Static));
            return request;
        }

    }
}